package com.yzt.dynamicmodule.adapter;

import androidx.annotation.NonNull;

import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.PoiInfo;
import com.baidu.mapapi.utils.DistanceUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.yzt.dynamicmodule.R;
import com.yzt.zhuju.utils.FormatUtils;

/**
 * 作者：bobwang
 * 创建时间：2023-11-19 21:19:07
 * 描述：
 */
public class GameAddCityAdapter extends BaseQuickAdapter<PoiInfo, BaseViewHolder> {

    private double latitude, longitude;

    public void setPlaceLatLng(double latitude1, double longitude1) {
        latitude = latitude1;
        longitude = longitude1;
    }

    public GameAddCityAdapter() {
        super(R.layout.item_game_add_city);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, PoiInfo bean) {
        holder.setText(R.id.tv_name, bean.getName())
                .setText(R.id.tv_content, bean.getAddress());
        LatLng placeLatLng = new LatLng(latitude, longitude);
        LatLng targetLatLng = new LatLng(bean.getLocation().latitude, bean.getLocation().longitude);
        double distance = DistanceUtil.getDistance(placeLatLng, targetLatLng);
        if (distance < 1000) {
            holder.setText(R.id.tv_distance, FormatUtils.formatKeepOne(distance) + "米");
        } else {
            holder.setText(R.id.tv_distance, FormatUtils.formatKeepOne(distance / 1000) + "公里");
        }
    }
}
